package com.yxym.encap;
/*
    1.创建程序，在其中定义两个类：Account,和AccountTest类
    2.Account具有属性：姓名（长度为2到4位），余额（大于20）
    3.密码为6位，也可根据提示信息，给出默认值
    4.通过setXxx的方法给Account的属性赋值
    5.在AccountTest中测试
     */

public class Account {
    private  String name;
    private double balance;
    private String password;

    //设置无参构造器
    public Account(){

    }
    public Account(String name,double balance ,String password) {
        this.name = name;
        this.balance =balance;
        this.password =password;
        setBalance(balance);
        setName(name);
        setPassword(password);
    }

//    public String getName() {
//        return name;
//    }
//Account具有属性：姓名（长度为2到4位）
    public void setName(String name) {
        if(name.length() <= 4 && name.length() >=2 ){
            this.name = name;
        }else{
            System.out.println("输入的名字长度不对，重新输入（范围为2-4）");
            this.name = " 无名氏 ";
        }
    }

//    public double getBalance() {
//        return balance;
//    }
//余额（大于20）
    public void setBalance(double balance) {
        if(balance > 20.0){
            this.balance = balance;
        }else{
            System.out.println("余额输入默认值");
            this.balance = 0.0;
        }
    }

//    public String getPassword() {
//        return password;
//    }

    public void setPassword(String password) {
        if(password.length()==6){
            this.password = password;
        }else{
            System.out.println("密码必须是6位！");
            this.password = "000000";
        }
    }
    //显示账号信息
    public String info(){
        return "输出信息为：" + "name = " + name+ "\t" + "banace = " + balance
                + "\t" + "password = " + password;
    }
}


